package com.peter.rest;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;

import java.net.MalformedURLException;

/**
 * @program: Learning
 * @description:
 * @Company: 汇华(北京)信息咨询服务有限公司
 * @author: peter.wei
 * @create: 2020-08-06 11:28
 **/
public class TestPost {

    @Autowired
    private RestTemplateConfig restTemplateConfig;

    public void testPostMethod() throws MalformedURLException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("startTime", "2020-01-01 12:00:00");
        jsonObject.put("endTime", "2020-01-02 12:00:00");
        HttpHeaders httpHeaders = new HttpHeaders();
        // 设置请求类型
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        // 封装参数和头信息
        HttpEntity<JSONObject> httpEntity = new HttpEntity(jsonObject, httpHeaders);
        String url = "http://117.34.72.208:30093/cbi-datamanager-provider/work-time-controller/getWorkTimeUsingPOST";
        ResponseEntity<String> mapResponseEntity = restTemplateConfig.restTemplate().postForEntity(url, httpEntity, String.class);
        System.out.println(mapResponseEntity.getBody());
    }
}